package com.elysia.visionmanagerspringboot.config;

import com.aliyun.mts20140618.Client;
import com.aliyun.teaopenapi.models.Config;
import com.elysia.visionmanagerspringboot.properties.AliyunMtsProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 阿里云MTS客户端配置类，用于创建并注册MTS Client实例
 */
@Configuration
@RequiredArgsConstructor
public class AliyunMtsConfiguration {

    private final AliyunMtsProperties aliyunMtsProperties;

    /**
     * 创建阿里云MTS客户端实例并注册到Spring容器
     */
    @Bean
    public Client mtsClient() throws Exception {
        Config config = new Config()
                .setAccessKeyId(aliyunMtsProperties.getAccessKeyId())
                .setAccessKeySecret(aliyunMtsProperties.getAccessKeySecret())
                // 补充 MTS Endpoint：格式为 mts.{regionId}.aliyuncs.com
                .setEndpoint("mts." + aliyunMtsProperties.getRegionId() + ".aliyuncs.com");
        config.regionId = aliyunMtsProperties.getRegionId();
        return new Client(config);
    }
}
